package com.yuqian.JavaSe.thread.cap1.title2;

/**
 * 学习线程类Thread 
 * 1.线程的创建 
 * 2.线程的启动 
 * 3.线程的停止 
 * 4.线程的优先级 
 * 5.线程的安全
 * 
 * @author yuqian
 *线程的随机性
 */
public class MyThread extends Thread {
	
	@Override
	public void run() {
		try {
			for(int i=0;i<10;i++){
				int sleepTime = (int) (Math.random()*1000);
				Thread.sleep(sleepTime);
				System.out.println("CurrentThread:"+Thread.currentThread().getName());
				
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		try {
			MyThread my = new MyThread();
			my.setName("MyThread");
			my.start();
			for(int i=0;i<10;i++){
				int sleepTime = (int) (Math.random()*1000);
				Thread.sleep(sleepTime);
				System.out.println("CurrentThread:"+Thread.currentThread().getName());
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
